#include<iostream>
#include<algorithm>
using namespace std;

typedef pair<int,int> PII;
const int N=50010;
#define x first
#define y second

int n;
PII cow[N];

int main()
{
    cin >> n;
    for(int i=0;i<n;i++)
    {
        int w,s;
        cin >> w >> s;
        cow[i] = {w+s,w};
    }
    sort(cow,cow+n);
    int res = -1e9,sum=0;
    for(int i=0;i<n;i++)
    {
        int s;
        s = cow[i].x-cow[i].y;
        res = max(res,sum-s);//风险 = 上面的重量-当前的承受
        sum+=cow[i].y;
    }
    cout << res;
    return 0;
}
